﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using OgilvyOne.BLL;
using OgilvyOne.Model;
using System.Collections;
using ECCIT;
using ECCIT.Web;
using OgilvyOne.UKNow.Model;
using OgilvyOne.UKNow.BLL;
using OgilvyOne.UKNow.Globalization;
using System.IO;
using System.Configuration;

public partial class admin_UKNOW_SyncEvents : System.Web.UI.Page
{

    HomeVideoBll hvb = new HomeVideoBll();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
          
            List<HomeVideo> lhv=   new HomeVideoBll().GetAllModList();
            HomeVideo hvi=lhv!=null?lhv[0]:null;
            if (hvi!=null)
            {
                txtVideoName.Text = hvi.VideoName;
                txtVideoDesp.Text = hvi.VideoDesc;
                if (hvi.Id!="")
                {
                    hidID.Value = hvi.Id;
                }
            }
            
            
           
        }
    }

    protected void btnOk_Click(object sender, EventArgs e)
    {
        if (hidID.Value == "$")
        {
            if (hvb.add(tomod())) { Response.Write("<script>alert('上传成功')</script>"); };
        }
        else
        {
            if (hvb.update(tomod(), hidID.Value)) { Response.Write("<script>alert('上传成功')</script>"); };
        }

    }
    protected  HomeVideo tomod()
    {    
        HomeVideo hv =null;
        if (hidID.Value == "$")
        {
            hv = new HomeVideo();
            hv.Id = Guid.NewGuid().ToString();
            hv.InsertTime = DateTime.Now;

            hv.VideoUrl = upfile();

        }
        else
        {
            hv = hvb.GetAllModList()[0];

            hv.VideoName = txtVideoName.Text;
            if (upVideo.HasFile)
            {
                hv.VideoUrl = upfile();
            }
            
            
        }
        hv.VideoName = txtVideoName.Text;
        hv.VideoDesc = txtVideoDesp.Text;
        hv.UpdateTime = DateTime.Now;
        return hv;

    }
    private string  upfile()
    {
       string path=Guid.NewGuid().ToString()+upVideo.FileName.Substring(upVideo.FileName.LastIndexOf("."));
        string vpath=String.Format("{0}{1}",ConfigurationManager.AppSettings["vpath"],path);
        //ECCIT.IO.DataItemPath dp=new ECCIT.IO.DataItemPath ( vpath,ECCIT.IO.PathType.VirtualPath);
        //UploadedFile.Save(upVideo, dp, null);
        upVideo.SaveAs(Server.MapPath(vpath));
        return path;
    }
    protected void ss(object sender, EventArgs e)
    {

    }
   
}